import 'package:flutter/material.dart';
import 'package:hugeicons/hugeicons.dart';
import 'package:provider/provider.dart';
import 'package:tool/base/base_widget.dart';

import '../../base/base_state.dart';
import '../../resources.dart';
import 'm/file_item_model.dart';
import 'vm/file_model.dart';

class FilePage extends StatefulWidget {
  const FilePage({super.key});

  @override
  State<StatefulWidget> createState() => _FileState();
}

class _FileState extends BaseWidgetState<FileModel, FilePage> {
  @override
  bool get wantKeepAlive => true;

  @override
  FileModel initModel() {
    return FileModel();
  }

  @override
  Widget bodyWidget(BuildContext context) {
    return Container(
      width: designWidth.ss,
      height: double.infinity,
      color: Colors.transparent,
      child: Column(
        children: [
          commonTitleBar(word.file_title,
              titleBackColor: ColorUtils.color_3C6EF0),
          Expanded(
            child: _buildList(),
          ),
        ],
      ),
    );
  }

  Widget _buildList() {
    return GridView.builder(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
            childAspectRatio: 1,
            crossAxisSpacing: 12.ss,
            mainAxisSpacing: 24.ss),
        shrinkWrap: true,
        physics: const BouncingScrollPhysics(),
        itemCount: model.buttons.length,
        itemBuilder: (context, index) {
          var button = model.buttons[index];
          var icon = model.icons[index];
          return InkWell(
            onTap: () {
              model.goManager(index);
            },
            child: Container(
              decoration: BoxDecoration(
                  color: Colors.transparent,
                  borderRadius: BorderRadius.circular(8.ss)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    width: 50.ss,
                    height: 50.ss,
                    decoration: BoxDecoration(
                        color: ColorUtils.app_color.withOpacity(0.8),
                        borderRadius: BorderRadius.circular(15.ss)),
                    child: HugeIcon(
                        icon: icon,
                        color: ColorUtils.color_D4AC5B,
                        size: 32.ss),
                  ),
                  SizedBox(height: 3.ss),
                  Text(button.title, style: normal312)
                ],
              ),
            ),
          );
        });
  }
}
